package com.platform.web.controller.report;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.module.domain.BaseRoomTemp;
import com.platform.module.domain.BaseValveData;
import com.platform.module.domain.BaseValveType;
import com.platform.module.domain.TempRecord;
import com.platform.module.service.IBaseRoomTempService;
import com.platform.module.service.ITempRecordService;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 温度采集曲线图控制类
 *
 * @author wangqi
 * @date 2020-08-04
 */
@Controller
@RequestMapping("/report/temp")
public class TempReportController extends BaseController {

    private String prefix = "report/temp";

    @Autowired
    private IBaseRoomTempService baseRoomTempService;

    @Autowired
    private ITempRecordService tempRecordService;

    @RequiresPermissions("report:temp:view")
    @GetMapping()
    public String temp(ModelMap mmap)
    {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        mmap.put("beginTime", dateFormat.format(new Date()));
        mmap.put("endTime", dateFormat.format(new Date()));
        return prefix + "/temp";
    }

    /**
     * 室温变化曲线图
     */
    @PostMapping("/tempSummary")
    @ResponseBody
    public AjaxResult tempSummary(TempRecord tempRecord)
    {
        if(tempRecord.getParams().get("beginTime").equals("") && tempRecord.getParams().get("endTime").equals("")){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            tempRecord.getParams().put("beginTime", simpleDateFormat.format(new Date()));
            tempRecord.getParams().put("endTime", simpleDateFormat.format(new Date()));
        }
        List<TempRecord> tempRecordList  = tempRecordService.selectTempRecordList(tempRecord);
        return AjaxResult.success(tempRecordList);
    }
}
